package com.hqyj.controller;

import com.hqyj.exception.UserInfoException;
import com.hqyj.pojo.UserInfo;
import com.hqyj.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * 项目:demo-springboot-230701
 * 描述:
 * 时间:2023/9/26 10:52
 * 作者:admin
 * 版本:1.0
 **/
@RestController
@RequestMapping("/user")
public class UserInfoController {

    @Autowired
    UserInfoService userInfoService;
    //新增
    @PostMapping("/user")
    public HashMap<String,Object> add(@RequestBody UserInfo userInfo) throws UserInfoException {
        return userInfoService.add(userInfo);
    }
    //修改
    @PutMapping("/user")
    public HashMap<String,Object> update(@RequestBody UserInfo userInfo){
        return userInfoService.update(userInfo);
    }
    //删除
    @DeleteMapping("/user")
    public HashMap<String,Object> del(Integer id){
        return userInfoService.del(id);
    }
    //查询
    @GetMapping("/user")
    public HashMap<String,Object> searhc(UserInfo userInfo){
        return userInfoService.search(userInfo);
    }
    //批量新增
    @PostMapping("/user/user")
    public HashMap<String,Object> add(@RequestBody List<UserInfo> list){
        return userInfoService.addBitch(list);
    }
    //批量修改
    @PutMapping("/user/user")
    public HashMap<String,Object> update(@RequestBody List<UserInfo> list){
        return userInfoService.updateBitch(list);
    }
    //批量删除
    @DeleteMapping("/user/user")
    public HashMap<String,Object> del(@RequestBody List<Integer> list){
        return userInfoService.delBitch(list);
    }
    //批量查询
    @GetMapping("/user/user")
    public HashMap<String,Object> searchBitch(@RequestBody List<Integer> list){
        return userInfoService.searchBitch(list);
    }
    //动态查询
    @GetMapping("/user/user/user")
    public HashMap<String,Object> searchByCondition(@RequestBody UserInfo userInfo){
        return userInfoService.searchByCondition(userInfo);
    }
    //分页查询
    @GetMapping("/user/page")
    public HashMap<String,Object> searchPage(@RequestBody UserInfo userInfo){
        return userInfoService.searchPage(userInfo);
    }
    //登录
    @PostMapping("/user/login")
    public HashMap<String,Object> login(@RequestBody UserInfo userInfo){
        return userInfoService.login(userInfo);
    }


}
